import { useRequest } from "ahooks";
import { request } from "@/utils/request";

import { EditUserDataType } from "@/types/user";

interface UpdateUserAccountStatusDataType {
  id: number;
  userId: number;
  status?: "pending" | "verified" | "denied";
  reason?: string;
}

interface UnBindAccountDataType {
  id: number;
  userId: number;
}

export const fetchUserList = async (params: any) => {
  const response = await request("/v1/admin/user/list", {
    method: "GET",
    params,
  });
  return response;
};

export const useUserList = () => {
  return useRequest((params: any) => fetchUserList(params), {
    manual: true, // 改为手动触发
  });
};

export const fetchUserAccountList = async (params: any) => {
  const response = await request("/v1/admin/account/list", {
    method: "GET",
    params,
  });
  return response;
};

export const useUserAccountList = () => {
  return useRequest((params: any) => fetchUserAccountList(params), {
    manual: true,
  });
};

export const editUser = async (data: EditUserDataType) => {
  const response = await request(`/v1/admin/user/${data.id}`, {
    method: "PUT",
    body: JSON.stringify(data),
  });
  return response;
};

// 更新账号状态（通过/驳回统一接口）
export const updateUserAccountStatus = async (data: UpdateUserAccountStatusDataType) => {
  const response = await request(`/v1/admin/account/audit`, {
    method: "POST",
    body: JSON.stringify(data),
  });
  return response;
};

// 解绑
export const unbindUserAccount = async (data: UnBindAccountDataType) => {
  const response = await request(`/v1/admin/account/unbind`, {
    method: "POST",
    body: JSON.stringify(data),
  });
  return response;
};

// 名片
export const fetchCardList = async (params: any) => {
  console.log("params: ", params);
  const response = await request("/v1/admin/business_card/list", {
    method: "GET",
    params,
  });
  return response;
};

export const useCardList = () => {
  return useRequest((params: any) => fetchCardList(params), {
    manual: true, // 改为手动触发
  });
};
